import { Ab_DataTransfer_bA } from "../../A-FRAME/A-LIB/lib.b.data";
import Ab_GlobalDC_bA from "../../A-FRAME/common/data.global.center";
import { Ab_APP_NAME_bA } from "../../A-FRAME/frame.config";
import { Ab_ClientAPI_bA } from "../api/client.api";
import Ab_Config_bA from "./config.manager";
import Ab_GameDC_bA from "./data.game.center";
import Ab_GameAssets_bA from "./game.assets";

export default class Ab_GameManager_bA {

	public static async Ab_init_bA(country: string){
		await Ab_Config_bA.Ab_init_bA(country);
		await Ab_GameAssets_bA.Ab_init_bA(Ab_Config_bA.Ab_country_bA, Ab_Config_bA.Ab_language_bA);

		Ab_GlobalDC_bA.Ab_init_bA();
		Ab_GameDC_bA.Ab_init_bA();
		Ab_GameDC_bA.Ab_Status_bA.Ab_deviceID_bA = (await Ab_ClientAPI_bA.Ab_DeviceID_bA()).Ab_device_id_bA;
		if(!Ab_GameDC_bA.Ab_User_bA.Ab_nickname_bA) await Ab_GameManager_bA.Ab_initUser_bA();

		Ab_GameManager_bA.Ab_listening_bA();
	}

	private static async Ab_initUser_bA(){
		Ab_GameDC_bA.Ab_User_bA.Ab_nickname_bA = Ab_GameAssets_bA.Ab_getNickname_bA();
	}


	private static Ab_listening_bA(){
		if(Ab_GlobalDC_bA.Ab_Trigger_bA.Ab_NEW_DAY_bA) this.Ab_newDay_bA();
		else this.Ab_checkEmpty_bA();

		Ab_DataTransfer_bA.Ab_follow_bA(Ab_GlobalDC_bA.Ab_Trigger_bA, 'Ab_NEW_DAY_bA', (_, _new_)=>{
			if(_new_) Ab_GameManager_bA.Ab_newDay_bA();
			else Ab_GameManager_bA.Ab_checkEmpty_bA();
		}, false);
	}

	private static Ab_initRankList_bA(){
		Ab_GameDC_bA.Ab_initRankData_bA(Ab_GameAssets_bA.Ab_Nickname_bA, Ab_Config_bA.Ab_officialConf_bA.rank_a, Ab_Config_bA.Ab_officialConf_bA.rank_b);
	}

	private static Ab_newDay_bA(){
		Ab_GameManager_bA.Ab_initRankList_bA();
	}

	private static Ab_checkEmpty_bA(){
		let rank_list = abi.Ab_local_bA.Ab_read_bA(Ab_APP_NAME_bA + 'rank_list');
		if(!rank_list) Ab_GameManager_bA.Ab_initRankList_bA();
	}
}